package leetcode

func isPalindrome1(s string) bool {
	count := len(s)
	if count == 0 {
		return true
	}

	arr := make([]byte, 0, count)
	for i := 0; i < count; i++ {
		switch {
		case 'a' <= s[i] && s[i] <= 'z':
			arr = append(arr, s[i])
		case 'A' <= s[i] && s[i] <= 'Z':
			arr = append(arr, s[i]+('a'-'A'))
		case '0' <= s[i] && s[i] <= '9':
			arr = append(arr, s[i])
		}
	}

	count = len(arr)
	if count == 0 {
		return true
	}

	for i := 0; i < count/2; i++ {
		if arr[i] != arr[count-1-i] {
			return false
		}
	}

	return true
}

func isPalindrome(s string) bool {
	count := len(s)
	if count == 0 {
		return true
	}

	var left, right byte
	for i, j := 0, count-1; i <= j; i, j = i+1, j-1 {
		for i <= j {
			switch {
			case 'a' <= s[i] && s[i] <= 'z', '0' <= s[i] && s[i] <= '9':
				left = s[i]
			case 'A' <= s[i] && s[i] <= 'Z':
				left = s[i] + ('a' - 'A')
			default:
				i++
				continue
			}

			break
		}

		for i <= j {
			switch {
			case 'a' <= s[j] && s[j] <= 'z', '0' <= s[j] && s[j] <= '9':
				right = s[j]
			case 'A' <= s[j] && s[j] <= 'Z':
				right = s[j] + ('a' - 'A')
			default:
				j--
				continue
			}

			break
		}

		if left != right {
			return false
		}
	}

	return true
}
